package com.atguigu.tingshu.album.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseAttribute;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value="/api/album/category")
@SuppressWarnings({"all"})
@Slf4j
public class BaseCategoryApiController {

	@Autowired
	private BaseCategoryService baseCategoryService;

	//http://127.0.0.1/api/album/category/getBaseCategoryList
	@GetMapping("getBaseCategoryList")
	@Operation(summary = "获取分类接口")
	public Result getBaseCategoryList(){
		log.info("获取分类");
		List<JSONObject> list = baseCategoryService.getBaseCategoryList();
		return Result.ok(list);
	}




	/**
	 * 根据分类id查询数据
	 * @param categoryId
	 * @return
	 */
	//http://127.0.0.1/api/album/category/findAttribute/2
	@Operation(summary = "根据分类id查询数据")
	@GetMapping("/findAttribute/{categoryId}")
	public Result findAttributeBycategoryId(@PathVariable Long categoryId){
		log.info("根据分类id查询数据:{}",categoryId);
		List<BaseAttribute> attributeList = this.baseCategoryService.findAttributeBycategoryId(categoryId);
		return Result.ok(attributeList);
	}

	/**
	 * 根据三级分类Id 获取到分类数据
	 * @param category3Id
	 * @return
	 */
	@Operation(summary = "根据三级分类Id 获取到分类数据")
	@GetMapping("/getCategoryView/{category3Id}")
	public Result<BaseCategoryView> getCategoryView(@PathVariable Long category3Id){
		BaseCategoryView baseCategoryView = baseCategoryService.getCategoryViewByCategory3Id(category3Id);
		return Result.ok(baseCategoryView);
	}

}

